PIC24F
Comparator Peripheral Module Library Help


Table Of Contents

1     Library Features. 3

2     Using Functions in Your Code. 3

3     Functions. 3

3.1     Config_CMP. 3

4     Macros. 5

4.1     mCMP2_EnblDsbl(state) 5

4.2     mCMP1_EnblDsbl(state) 5

4.3     mCMP2_Output_EnblDsbl(state) 5

4.4     mCMP1_Output_EnblDsbl(state) 5

4.5     mCMP2_Get_STATE(state) 5

4.6     mCMP1_Get_STATE(state) 6

 


1          Library Features

 

This peripheral library module:

 

·         Provides two ranges of output voltage, each with 16 distinct levels.

·         Can come from either VDD and VSS, or the external VREF+ and VREF-.

 

Note: The settling time of the comparator voltage reference must be considered when changing the CVREF output.

 

2          Using Functions in Your Code

 

Library routine parameters can be constructed using either AND based mask or AND_OR based mask setting. For more information on these masks, see 16-bit Peripheral Libraries.

 

Example of Use ( AND_OR mask )

 

Function Call

 

Config_CMP((CMP_IDLE_STOP | CMP2_NO_CHANGE | CMP1_CHANGE_STATE

            | CMP2_DISABLE | CMP1_ENABLE | CMP2_OUTPUT_DISABLE

            | CMP1_OUTPUT_ENABLE | CMP2_NORMAL_OUTPUT

            | CMP1_NORMAL_OUTPUT | CMP2_NEG_IP_Vin_Pos

            | CMP2_POS_IP_Vin_Pos | CMP1_NEG_IP_Vin_Pos

            | CMP1_POS_IP_Vin_Pos),(CMP_VRef_Enable

            | CMP_VRef_OUTPUT_Enable | CMP_VRef_SELECT_24_STEPS

            | CMP_Vrsrc_Vref_Vref | CMP_0p0CVrsrc_OR_0p25CVrsrc) ) ;

 

3          Functions

3.1         Config_CMP

 

Function Prototype

void Config_CMP(UINT16 config1 , UINT16 config2)

Include

comparator.h

Description

This routine configures Reference Voltage level and Comparator module.

Arguments

config1 - This contains the parameters to be configured in the CVRCON register as defined below

Stop in Idle Mode

   CMP_IDLE_STOP

   CMP_IDLE_CON

Comparator 2 Event

   CMP2_CHANGE_STATE

   CMP2_NO_CHANGE

Comparator 1 Event

   CMP1_CHANGE_STATE

   CMP1_NO_CHANGE

Comparator 2 Enable

   CMP2_ENABLE

   CMP2_DISABLE

Comparator 1 Enable

   CMP1_ENABLE

   CMP1_DISABLE

Comparator 2 Output Enable

   CMP2_OUTPUT_ENABLE

   CMP2_OUTPUT_DISABLE

Comparator 1 Output Enable

   CMP1_OUTPUT_ENABLE

   CMP1_OUTPUT_DISABLE

Comparator 2 Output Inversion bit

   CMP2_INV_OUTPUT

   CMP2_NORMAL_OUTPUT

Comparator 1 Output Inversion bit

   CMP1_INV_OUTPUT

   CMP1_NORMAL_OUTPUT

Comparator 2 Negative Input Configure bit

   CMP2_NEG_IP_Vin_Pos

   CMP2_NEG_IP_Vin_Neg

Comparator 2 Positive Input Configure bit

   CMP2_POS_IP_Vin_Pos

   CMP2_POS_IP_CV_Ref

Comparator 1 Negative Input Configure bit

   CMP1_NEG_IP_Vin_Pos

   CMP1_NEG_IP_Vin_Neg

Comparator 1 Positive Input Configure bit

   CMP1_POS_IP_Vin_Pos

   CMP1_POS_IP_CV_Ref

 

config2 - This contains the parameters to be configured in the CMCON Register as defined below

Comparator Voltage Reference Enable bit

   CMP_VRef_Enable

   CMP_VRef_Disable

Comparator VREF Output Enable bit

   CMP_VRef_OUTPUT_Enable

   CMP_VRef_OUTPUT_Disable

Comparator VREF Range Selection bit

   CMP_VRef_SELECT_24_STEPS

   CMP_VRef_SELECT_32_STEPS

Comparator VREF Source Selection bit

   CMP_Vrsrc_Vref_Vref

   CMP_Vrsrc_AVDD_AVSS

Comparator VREF Value Selection 0 CVR3:CVR0 15 bits

   CMP_0p0CVrsrc_OR_0p25CVrsrc

   CMP_0p04CVrsrc_OR_0p28CVrsrc

   CMP_0p08CVrsrc_OR_0p31CVrsrc

   CMP_0p12CVrsrc_OR_0p34CVrsrc

   CMP_0p16CVrsrc_OR_0p37CVrsrc

   CMP_0p20CVrsrc_OR_0p40CVrsrc

   CMP_0p25CVrsrc_OR_0p43CVrsrc

   CMP_0p29CVrsrc_OR_0p46CVrsrc

   CMP_0p33CVrsrc_OR_0p50CVrsrc

   CMP_0p37CVrsrc_OR_0p53CVrsrc

   CMP_0p41CVrsrc_OR_0p56CVrsrc

   CMP_0p45CVrsrc_OR_0p59CVrsrc

   CMP_0p50CVrsrc_OR_0p62CVrsrc

   CMP_0p54CVrsrc_OR_0p65CVrsrc

   CMP_0p58CVrsrc_OR_0p68CVrsrc

   CMP_0p62CVrsrc_OR_0p71CVrsrc

Return Value

None

Remarks:

None

Source File:

Config_CMP.c

 

4          Macros

4.1         mCMP2_EnblDsbl(state)

 

Macro

mCMP2_EnblDsbl(state)

Include

comparator.h

Description

Macro Enables/Disables the Comparator 2

Arguments

state = 1 Comparator is enabled

state = 0 Comparator is disabled

Remarks

None

4.2         mCMP1_EnblDsbl(state)

 

Macro

mCMP1_EnblDsbl(state)

Include

comparator.h

Description

Macro Enables/Disables the Comparator 1

Arguments

state = 1 Comparator is enabled

state = 0 Comparator is disabled

Remarks

None

4.3         mCMP2_Output_EnblDsbl(state)

 

Macro

mCMP2_Output_EnblDsbl(state)

Include

comparator.h

Description

Macro Enables/Disables Comparator 2 output on the output pad

Arguments

state = 1 Comparator output driven on the output pad

state = 0 Comparator output is not driven on the output pad

Remarks

None

4.4         mCMP1_Output_EnblDsbl(state)

 

Macro

mCMP1_Output_EnblDsbl(state)

Include

comparator.h

Description

Macro Enables/Disables Comparator 1 output on the output pad

Arguments

state = 1 Comparator output driven on the output pad

state = 0 Comparator output is not driven on the output pad

Remarks

None

4.5         mCMP2_Get_STATE(state)

 

Macro

mCMP2_Get_STATE(state)

Include

comparator.h

Description

Macro Returns state of Comparator output

When  C2INV = 0:

state = 1 : C2 VIN+ > C2 VIN-

state = 0 : C2 VIN+ < C2 VIN

When C2INV = 1:

state = 0 : C2 VIN+ > C2 VIN-

state = 1 : C2 VIN+ < C2 VIN-

Arguments

None

Remarks

State of Comparator depends on Inverse selection bit in control register

4.6         mCMP1_Get_STATE(state)

 

Macro

mCMP1_Get_STATE(state)

Include

comparator.h

Description

Macro Returns state of Comparator output

When  C1INV = 0:

state = 1 : C1 VIN+ > C1 VIN-

state = 0 : C1 VIN+ < C1 VIN

When   C1INV = 1:

state = 0 : C1 VIN+ > C1 VIN-

state = 1 : C1 VIN+ < C1 VIN-

Arguments

None

Remarks

State of Comparator depends on Inverse selection bit in control register